<template>
    <div class="layout-container">
        <el-container>
            <el-header height="60px">
                <div class="header-container">
                    <div class="logo">
                        <h1>拍卖交易系统管理后台</h1>
                    </div>
                    <div class="user-info">
                        <el-dropdown trigger="click" @command="handleCommand">
                            <span class="user-dropdown">
                                {{ adminName }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
                            </span>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item command="profile">个人信息</el-dropdown-item>
                                    <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                </div>
            </el-header>

            <el-container>
                <el-aside width="200px">
                    <el-menu :default-active="activeMenu" class="el-menu-vertical" :collapse="isCollapse"
                        @select="handleSelect" background-color="#304156" text-color="#bfcbd9"
                        active-text-color="#409EFF" router>
                        <el-menu-item index="/admin">
                            <el-icon>
                                <Monitor />
                            </el-icon>
                            <span>控制台</span>
                        </el-menu-item>

                        <!-- 竞价管理 -->
                        <el-menu-item index="/admin/bid">
                            <el-icon>
                                <Timer />
                            </el-icon>
                            <span>竞价管理</span>
                        </el-menu-item>

                        <!-- 订单管理 -->
                        <el-menu-item index="/admin/order">
                            <el-icon>
                                <Document />
                            </el-icon>
                            <span>订单管理</span>
                        </el-menu-item>

                        <el-sub-menu index="2">
                            <template #title>
                                <el-icon>
                                    <user />
                                </el-icon>
                                <span>用户管理</span>
                            </template>
                            <el-menu-item index="/admin/users">用户列表</el-menu-item>
                        </el-sub-menu>

                        <el-sub-menu index="3">
                            <template #title>
                                <el-icon>
                                    <shop />
                                </el-icon>
                                <span>卖家管理</span>
                            </template>
                            <el-menu-item index="/admin/sellers">卖家列表</el-menu-item>
                            <el-menu-item index="/admin/seller-applications">入驻申请</el-menu-item>
                        </el-sub-menu>

                        <!-- 拍卖品管理 -->
                        <el-sub-menu index="4">
                            <template #title>
                                <el-icon>
                                    <Goods />
                                </el-icon>
                                <span>拍卖品管理</span>
                            </template>
                            <el-menu-item index="/admin/auctions">拍卖列表</el-menu-item>
                            <el-menu-item index="/admin/categories">分类管理</el-menu-item>
                        </el-sub-menu>

                        <el-menu-item index="/admin/profile">
                            <el-icon>
                                <setting />
                            </el-icon>
                            <span>管理员信息</span>
                        </el-menu-item>
                    </el-menu>
                </el-aside>

                <el-main>
                    <router-view />
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useAdminStore } from '@/stores/admin'
import { ElMessageBox } from 'element-plus'
import { Monitor, Timer, Document, User, Shop, Menu, Goods, Setting } from '@element-plus/icons-vue'

const router = useRouter()
const adminStore = useAdminStore()

const adminName = computed(() => adminStore.userName || '管理员')

const handleCommand = (command) => {
    if (command === 'logout') {
        ElMessageBox.confirm('确定要退出登录吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            adminStore.logout()
            router.push('/login')
        }).catch(() => { })
    } else if (command === 'profile') {
        router.push('/admin/profile')
    }
}
</script>

<style scoped>
.layout-container {
    height: 100%;
}

.el-container {
    height: 100%;
}

.el-header {
    background-color: #304156;
    color: #fff;
    line-height: 60px;
    padding: 0 20px;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo h1 {
    margin: 0;
    font-size: 20px;
}

.user-dropdown {
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.el-aside {
    background-color: #304156;
}

.el-menu {
    border-right: none;
}

.el-menu-vertical:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
}
</style>